// ColumnModels
var projectSuperviseGrid_cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
			header : '项目编号',
			dataIndex : 'projectNumber',
			width : 110,
			sortable : true,
			locked : false
		}, {
			header : '项目名称',
			dataIndex : 'projectName',
			width : 150
		}, {
			header : '承办单位',
			dataIndex : 'undertakeUnitName',
			width : 80
		},{
			header : '项目负责人',
			dataIndex : 'projectDirectorName',
			width : 100
		},{
			header : '项目联系人',
			dataIndex : 'projectContactName',
			width : 100
		},{
			header : '跟进人',
			dataIndex : 'followUpPersonName',
			width : 100
		},
//		{
//			header : '项目跟进情况',
//			dataIndex : 'projectFollowUpSituation',
//			width : 50
//		},{
//			header : '项目状态',
//			dataIndex : 'projectState',
//			width : 50
//		},
		{
			header : '操作',
			dataIndex : 'projectNumber',
			renderer: superviseAction,
			width : 200
		}])
function superviseAction(val,p,record){
	var followUpSituation = record.get("projectFollowUpSituation");
	var projectState = record.get("projectState");
	action = "changeSupervise('" + val + "','" + followUpSituation + "','" + projectState + "');return false;";
	a = ' <a href="#" onclick="'+ action +'">查看监督管理情况</a>&nbsp;';
	return a;
}
var temp_superviseWindow;
var temp_projectNumber;
function changeSupervise(val,followupsituation,projectstate){
	//show window
	superviseWindow = new Ext.projectSuperviseWindow({
		title : "项目监督管理情况"
	});
	temp_projectNumber = val;
	temp_superviseWindow = superviseWindow;
	superviseWindow.findById("projectState_combo").setValue(projectstate);
	superviseWindow.findById("projectFollowUpSituation_textarea").setValue(followupsituation);
	superviseWindow.show();
}
Ext.projectSuperviseWindow = Ext.extend(Ext.Window,{
	initialized:false,
	modal:true,
	layout : 'fit',
	buttonAlign : 'center',
	buttons : [{
     	   xtype:'button',
     	   text : '保存',
     	   handler : function(){
	    		var state = temp_superviseWindow.findById("projectState_combo").getValue();
	    		var situation = temp_superviseWindow.findById("projectFollowUpSituation_textarea").getValue();
	    	    if(state == ""||state == null){
	    	    	Ext.Msg.alert("操作失败","请选择项目状态！");
	    	    	return;
	    	    }
	    	    if(temp_superviseWindow.findById("projectSuperviseFormPanel").form.isDirty()){
	    	    	Ext.Ajax.request({
		    	    	url : 'projectManage/projectManageAction!updateProjectSupervise',
		    	    	params : {
		    	    		pageMessage1 : temp_projectNumber,
		    	    		pageMessage5 : situation,
		    	    		pageMessage6 : state
		    	    	},
		    	    	success : function(){
		    	    		temp_superviseWindow.close();
							Ext.Msg.alert('操作成功', '成功保存监督管理信息');
							projectSuperviseStore.reload();
					    },
						failure : function(form, action) {
					    	temp_superviseWindow.close();
							Ext.Msg.alert('操作失败', '保存失败，请重新操作！');
						}
		    	    })
		    	    
	    	    }else{
//	    	    	Ext.Msg.alert("do nothing");
	    	    	temp_superviseWindow.close();
	    	    }
        }
        },{
     	   xtype : 'button',
     	   text : '关闭',
     	   handler : function(b, e){
        	temp_superviseWindow.close();
        }
        }],
        
	initComponent:function(){
	this.items = new Ext.form.FormPanel({
		id : 'projectSuperviseFormPanel',
		layout:'form',
		height : 330,
		width : 500,
		items:[new Ext.inquryProjectStateCombobox({
			id : 'projectState_combo',
			fieldLabel : "项目状态"
		}),{
			id : 'projectFollowUpSituation_textarea',
			xtype : 'textarea',
			width : 390,
			height : 300,
			fieldLabel : '项目跟进情况'
		}]});
	 	Ext.projectSuperviseWindow.superclass.initComponent.call(this);
}
})
var localStore = new Ext.data.ArrayStore({
	fields : ['projectState'],
    idIndex: 3		   	
});
//var test = [
//            ['s'],['d'],['v'],['f']];
var projectState = [
    	['实施阶段'],  
        ['完成未验收'],  
        ['已验收'],  
        ['已归档']    	
    	];
localStore.loadData(projectState);
Ext.inquryProjectStateCombobox = Ext.extend(Ext.form.ComboBox,{
	initialized : false,
	initComponent : function(){
	this.store = localStore;
	this.valueField = 'projectState';
	this.displayField = 'projectState';
    this.mode = 'local';
    this.editable = false;
    this.forceSelection = true;
    this.typeAhead = true;
    this.triggerAction = 'all';
    this.selectOnFocus = true;
    
    Ext.inquryProjectStateCombobox.superclass.initComponent.call(this);
	}
});
Ext.projectSuperviseGrid = Ext.extend(Ext.grid.GridPanel,{
	initialized:false,
	loadMask : true,
	loadData:function(){
	this.store.load({
		params:{
		start:0,
		limit:20
	}
	});
},
	initComponent:function(){
		this.store = projectSuperviseStore;
		this.stripeRows = true; 
		this.cm = projectSuperviseGrid_cm;
		this.tbar = [new Ext.inquryProjectCombobox({
			id: 'pm_inquryProjectSuperviseCombobox_id',
			width : 100,
			listeners : {
				"select" : function(combo, record, number) {
					var a = combo.findParentBy(function(ct,cmp){
						return (ct instanceof Ext.grid.GridPanel) ? true : false;
					});
					a.getTopToolbar().findById("pm_inquryProjectSuperviseTextfield_id").setValue();
			
		        }
								
			}
		}),new Ext.inquryProjectTextfield({
			id : 'pm_inquryProjectSuperviseTextfield_id'
		}),new Ext.inquryProjectButton({
			id:'pm_inquryProjectSuperviseButton_id',
			handler : function(b,e){
			var a = b.findParentBy(function(ct, cmp) { 
				return (ct instanceof Ext.grid.GridPanel) ? true : false; 
			});
			var combo_value = a.getTopToolbar().findById("pm_inquryProjectSuperviseCombobox_id").getValue();
			var text_value = a.getTopToolbar().findById("pm_inquryProjectSuperviseTextfield_id").getValue();
			if(combo_value == "" && text_value == ""){
//				Ext.Msg.alert("请选择查询字段并输入查询文本!");
//				return;
			}else if(combo_value == ""){
				Ext.Msg.alert("请选择查询字段!");
				return;
			}else if(text_value == ""){
				Ext.Msg.alert("请输入查询文本!");
				return;
			}
			projectSuperviseStore.on('beforeload',function(){
				projectSuperviseStore.baseParams = {
							pageMessage2 : getLoginId(),
							inquryText : text_value,
							type : combo_value
					}
				});
			    projectSuperviseStore.load({
					params : {
			    		pageMessage2 : getLoginId(),
						start : 0,
						limit : 20,
						inquryText : text_value,
						type : combo_value
				}
				});
				
			
		}
		})];
		this.bbar = new Ext.PagingToolbar({
			pageSize : 20,
			store : this.store,
			displayInfo : true,
			displayMsg : '显示 {0}-{1}条 / 共 {2} 条',
			emptyMsg : "无数据。",
			plugins : [new Ext.ux.PageSizePlugin()],
			items : ['-']
		});
        Ext.projectSuperviseGrid.superclass.initComponent.call(this);
              
}
})